home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 400 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: solon.com!not-for-mail
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion.
  5. Date: 15 Feb 1996 09:03:18 -0600
  6. Organization: CERN European Lab for Particle Physics
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4fvhvm$e8s@solutions.solon.com>
  10. References: <4fstj7$2l6@solutions.solon.com> <4fu835$9de@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: NN version 6.5.0 #7 (NOV)
  13.  
  14. >The final step is to convert the sum back to type `short'.  Here
  15. >things get a little fuzzy; comp.std.c has had arguments as to what
  16. >happens if the sum is `int', `int' is wider than `short', and the
  17. >sum is not representable as a `short'.  The Standard distinguishes
  18. >between `implicit' and `explicit' conversions, and this is an
  19. >`implicit' conversion (casts are the usual, perhaps the only, way
  20. >to write explicit conversions).  Some have argued that an explicit
  21. >conversion should never cause an overflow, but there seems to be
  22. >no wording in the standard to justify this position.  There appears
  23. >to be agreement that implicit conversion might overflow.  The
  24. >behavior on overflow would be undefined. 
  25.  
  26. This is a very common misconception.  From ANSI classic:
  27.  
  28.     3.2 CONVERSIONS
  29.  
  30.     Several operators convert operand values from one type to another
  31.     automatically.  This section specifies the result required from such
  32.     an implicit conversion, as well as those that result from a cast
  33.     ^^^^^^^^^^^^^^^^^^^^^^
  34.     operation (an explicit conversion).
  35. ...
  36.     3.2.1.2 Signed and unsigned integers
  37.  
  38.     When an integer is demoted to a signed integer with smaller size, or an
  39.     unsigned integer is converted to its corresponding signed integer, if
  40.     the value cannot be represented the result is implementation-defined.
  41.  
  42. Whoever agreed that the implicit conversion between integer types could
  43. cause undefined behaviour was in open conflict with the text of the
  44. standard (unless the standard was revised on this particular topic).
  45.  
  46. Dan
  47. --
  48. Dan Pop
  49. CERN, CN Division
  50. Email: danpop@mail.cern.ch 
  51. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  52.